package sfin.swt.util;

import java.util.ResourceBundle;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;

import sfin.swt.exception.StatizoException;

public class MessageUtil {

	private ResourceBundle bundle;
	private Shell shell;
	
	public MessageUtil(ResourceBundle bundle, Shell shell) {
		this.bundle = bundle;
		this.shell = shell;
	}
	
	public void showMessage(StatizoException ex){
		
		MessageBox message = new MessageBox(shell, SWT.ICON_ERROR);
		message.setText(bundle.getString("application.messages.error.onsave"));
		
		StringBuilder msgs = new StringBuilder();
		for(String msg:ex.getMessageList())
			msgs.append(msg).append("\n");
		
		message.setMessage(msgs.toString());
		message.open();
		
	}
	
	public void showMessage(StatizoException ex, Shell shell){
		
		MessageBox message = new MessageBox(shell, SWT.ICON_ERROR);
		message.setText(bundle.getString("application.messages.error.onsave"));
		
		StringBuilder msgs = new StringBuilder();
		for(String msg:ex.getMessageList())
			msgs.append(msg).append("\n");
		
		message.setMessage(msgs.toString());
		message.open();
		
	}

	
	public void showWarnMessage(String messageText){
		MessageBox message = new MessageBox(shell, SWT.ICON_ERROR);
		message.setText(bundle.getString("string.general.warn"));
		message.setMessage(messageText);
		message.open();
	}
	
}